<template>
  <div class="today">
    <!-- <div class="title">生鲜美味</div> -->
    <div class="goods-list">
      <el-row :gutter="20">
        <el-col
          v-for="(l, index) in list"
          :key="l.pid"
          :span="12"
          @click.native="goDetail(l)"
        >
          <div v-if="index < 2">
            <div class="grid-content">
              <img
                :src="l.cover_image"
                alt=""
              >

              <div class="goods-info">
                <div class="goods-name">
                  {{ l.name }}
                </div>
                <div class="goods-button">
                  查看详情<img
                    src="../../assets/img/more.png"
                    alt=""
                  >
                </div>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col
          v-for="(l, index) in list"
          :key="l.pid"
          :span="8"
          @click.native="goDetail(l)"
        >
          <div v-if="index >= 2 && index < 5">
            <div class="grid-content middle">
              <img
                :src="l.defaultAlbum"
                alt=""
              >

              <div class="goods-info">
                <div class="goods-name">
                  {{ l.name }}
                </div>
                <div class="goods-button">
                  查看详情<img
                    src="../../assets/img/more.png"
                    alt=""
                  >
                </div>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <!-- <div class="title">全部</div> -->
    <div
      v-if="list.length > 2"
      class="goods-list-f"
    >
      <div
        v-for="(item, index) in list"
        :key="index"
        class="goods-item"
        @click="todetail(item)"
      >
        <div v-if="index > 5">
          <div class="goods-img">
            <img
              :src="item.defaultAlbum"
              alt=""
            >
          </div>
          <div class="goods-info">
            <div class="name">
              {{ item.cProductShowName }}{{ item.cModelDescription }}
            </div>
            <div class="price">
              ￥{{ item.fSalePrice }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <div
      v-if="lastPage > page"
      class="more"
      @click="getMore"
    >
      点击加载更多+
    </div>
    <div
      v-else
      class="more"
    >
      没有更多
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  components: {},
  data() {
    return {
      list: [],
      page: 1,
      id: "",
      lastPage: 0,
    };
  },
  methods: {
    // 获取热门专题
    getData(getData) {
      this.id = getData;
      // 获取热门专题
      let param = {
        shop_id: getData,
        page: 1,
        limit: 12,
      }
      this.$api.home.topic(param).then((res) => {
        if (res.code == 1) {
          console.log('获取热门专题', res.data.data)
          this.list = this.list.concat(res.data.data);
          this.lastPage = res.data.last_page
        }
      });
    },
    //跳转商品详情
    goDetail(item) {
      console.log("ddd",item, item.id);
      this.$router.push({
        path: "/topicDetail",
        query: {
          id: item.id,
        },
      });
    },
    getMore() {
      this.page++;
      this.getData(this.id);
    },
  },
};
</script>

<style scoped lang="scss">
.today {
  padding: 0 16.19rem;
  margin-top: 2.19rem;
  display: flex;
  flex-direction: column;

  .title {
    width: 11.25rem;
    height: 3.44rem;
    background: rgba(0, 0, 0, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: rgba(234, 234, 234, 1);
  }

  .goods-list {
    margin-top: 1.88rem;
    width: 100%;

    .grid-content {
      border-radius: 4px;
      height: 27rem;
      background: #fff;
      margin-bottom: 1.31rem;
      display: flex;
      justify-content: space-around;
      align-items: center;
      cursor: pointer;
      > img {
        width: 17rem;
        height: 17rem;
        object-fit: contain;
        padding: 1rem;
      }
      .goods-info {
        display: flex;
        flex-direction: column;

        .goods-name {
          font-size: 1.38rem;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(0, 0, 0, 1);
          line-height: 2.42rem;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          width: 22rem;
        }
        .goods-price {
          font-size: 1.38rem;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: #f0406f;
          margin-top: 1.25rem;
          text-align: center;
        }
        .goods-button {
          width: 7.5rem;
          height: 1.88rem;
          background: rgba(4, 0, 0, 1);
          font-size: 0.88rem;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(255, 255, 255, 1);
          display: flex;
          justify-content: center;
          align-items: center;
          margin-top: 1.69rem;
          cursor: pointer;
          img {
            margin-left: 0.5rem;
            width: 1.06rem;
            height: 1.25rem;
          }
        }
      }
      &.middle {
        height: 23rem;
        > img {
          width: 10rem;
          height: 10rem;
          object-fit: contain;
          padding: 1rem;
        }
        .goods-info {
          display: flex;
          flex-direction: column;
          .goods-name {
            font-size: 1.38rem;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: rgba(0, 0, 0, 1);
            line-height: 2.42rem;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            width: 13rem;
          }
          .goods-button {
            width: 7.5rem;
            height: 2.19rem;
            background: rgba(4, 0, 0, 1);
            font-size: 0.88rem;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: rgba(255, 255, 255, 1);
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 1.69rem;
            cursor: pointer;
            img {
              margin-left: 0.5rem;
              width: 1.06rem;
              height: 1.25rem;
            }
          }
        }
      }
    }
  }
  // .more{
  // 	height:2.5rem;
  // 	background:rgba(0,0,0,1);
  // 	display: flex;
  // 	justify-content: flex-end;
  // 	align-items: center;
  // 	padding: 0 1.44rem;
  // 	img{
  // 		width: 7.38rem;
  // 		cursor: pointer;
  // 	}
  // }
  .adv {
    width: 100%;
    margin-top: 3.69rem;
    object-fit: contain;
  }
  .goods-list-f {
    margin-top: 1.88rem;
    width: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;

    .goods-item {
      width: 17.1rem;
      height: 25.88rem;
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-right: 1.33333%;
      margin-bottom: 2.38rem;
      cursor: pointer;

      &:nth-child(4n) {
        margin-right: 0;
      }

      .goods-img {
        width: 100%;
        height: 20.94rem;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #fff;

        img {
          width: 16rem;
          height: 16rem;
          object-fit: contain;
        }
      }

      .goods-info {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        margin-top: 1.5rem;

        .name {
          font-size: 1.13rem;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(0, 0, 0, 1);
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          width: 100%;
        }

        .price {
          font-size: 1.5rem;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(243, 64, 111, 1);
          margin-top: 0.75rem;
        }
      }
    }
  }
}
.more {
  font-size: 1rem;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(102, 102, 102, 1);
  line-height: 1.95rem;
  text-align: center;
  margin: 3.13rem auto;
  cursor: pointer;
}
</style>
